<?php
namespace Home\Model;
//物品基础属性
class Shop extends Container{
    protected $redis;
    protected $user;
    protected $type ;
    protected $index ;
    protected $username ;
    
    public function __construct($user){
        parent::__construct($user, 'shop');
        
    }

    public function initData(){
        //初始可以放10个家具
        //初始化等级
        $this->hSet('level', 0);
        $this->upgrade();
        // $this->add('武器台');
        // $this->add('炼铁台');
        // $this->add('锯木台');
        // $this->add('吧台');
        
    }

    //加家具,检查总空间是否足够
    public function add($name, $pre = false){
        $max = $this->getMax();
        if($max['current'] + 1> $max['max']) return false;
        if($pre) return true;
        return parent::add($name, 1);
    }

    public function get($name){
        return $this->hGet($name);
    }

    public function upgrade($currency = 'gold'){
        $info = cfg('container', 'shop');
        $level = $this->hGet('level');
        $level ++;
        $money = getClass('money', $this->user);
        if($money->dec($info[$currency][$level-1], $currency, true) === false) return error('金钱不足以升级店铺'.$info[$currency][$level]);
        //减钱
        $money->dec($info[$currency][$level-1], $currency);
        //加等级
        //加可启用家具数量
        $this->hMset(array('level'=> $level, 'max'=>$info['capcity'][$level-1]));
        //加员工插槽限制
        $worker = getClass('worker', $this->user);
        $worker->setMax($info['workers'][$level-1]);
    }
    
} 